<?php
/**
 * Created by PhpStorm.
 * 商家提现记录
 * User: caicm
 * Date: 2017/6/28
 * Time: 15:50
 */

namespace WMApi\Model;


use Think\Model;

class WmSellerWithdrawRecordModel extends Model {

    /**
     * 添加提现记录
     * Created By caicm
     * @param int $seller_id 商家id
     * @param string $withdraw_sn 提现单号
     * @param int $withdraw_money 提现金额
     * @param int $serv_charge 手续费
     * @param int $total_money 总金额
     * @param array $bank_card 银行卡信息
     * @return mixed
     */
    public function add_record($seller_id=0, $withdraw_sn='', $withdraw_money=0, $serv_charge=0, $total_money=0, $bank_card=array()){

        $data = array(
            'seller_id' => $seller_id,
            'withdraw_sn' => $withdraw_sn,
            'withdraw_money' => $withdraw_money,
            'serv_charge' => $serv_charge,
            'total_money' => $total_money,
            'bank_card_account' => $bank_card['bank_card_account'],
            'bank_card_number' => $bank_card['bank_card_number'],
            'bank_card_dbk' => $bank_card['bank_card_dbk'],
            'bank_card_subbranch' => $bank_card['bank_card_subbranch'],
            'bank_card_province_id' => $bank_card['bank_card_province_id'],
            'bank_card_province_name' => $bank_card['bank_card_province_name'],
            'bank_card_city_id' => $bank_card['bank_card_city_id'],
            'bank_card_city_name' => $bank_card['bank_card_city_name'],
            'bank_card_district_id' => $bank_card['bank_card_district_id'],
            'bank_card_district_name' => $bank_card['bank_card_district_name'],
            'withdraw_time' => gmtime(),
            'state' => 1,
            'audit_time' => 0,
            'audit_created' => '',
            'audit_remark' => '',
            'source' => get_source(),
            'version' => get_version()
        );

        return $this->data($data)->add();
    }

    /**
     * 获取提现记录详情
     * Created By caicm
     * @param int $seller_id
     * @param int $id
     * @return mixed
     */
    public function find_record_info($seller_id=0, $id=0){

        $where = array(
            'seller_id' => $seller_id,
            'id' => $id
        );

        return $this->where($where)->find();

    }

    /**
     * 获取商家提现记录列表
     * Created By caicm
     * @param int $seller_id
     * @return mixed
     */
    public function find_record_list($seller_id=0){

        $where = array(
            'seller_id' => $seller_id
        );

        return $this->where($where)->order('id desc')->select();

    }

    /**
     * 获取当月申请数量
     * Created By caicm
     * @param int $seller_id
     * @return mixed
     */
    public function get_withdraw_month_num($seller_id=0){
        //当月开始的时间戳
        $time= local_strtotime(date("Y-m"));

        $where = array(
            'seller_id' => $seller_id,
            'withdraw_time' => array('gt' => $time)
        );

        return $this->where($where)->count('id');

    }

    /**
     * 获取当月申请数量
     * Created By caicm
     * @param int $seller_id
     * @return mixed
     */
    public function get_withdraw_month_new_info($seller_id=0){
        //当月开始的时间戳
        $time= local_strtotime(date("Y-m"));

        $where = array(
            'seller_id' => $seller_id,
            'withdraw_time' => array('gt' => $time)
        );

        return $this->where($where)->order('id desc')->find();

    }

}